package com.marvels.dubbo.coreservice.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.coreservice.dto.DecisionMsgDTO;
import com.marvels.dubbo.coreservice.service.MarvelDecisionService;

/**决策调用控制层
 * @author 娄凯琦
 * @date 2018年9月21日  
 */

@RequestMapping("dubbo/core/marvelDecision/api")
@RestController
public class MarvelDecisionController {

	@Autowired
	private MarvelDecisionService marvelDecisionService;
	
	
	
	/**调用决策试算审批核定金额
	 * @author 娄凯琦
	 * @date 2018年9月21日  
	 * @param decisionMsgDTO
	 * @return
	 */
	@RequestMapping("trailApproveAmount")
	@ResponseBody
	public MarvelsResultDTO trailApproveAmount(@RequestBody DecisionMsgDTO decisionMsgDTO){
		try {
			MarvelsLogUtil.getInstance().info("DecisionController class trailApproveAmount the method start ==>" + decisionMsgDTO);
			DecisionMsgDTO decisionMsg = marvelDecisionService.trailApprovedAmount(decisionMsgDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),decisionMsg);
		}catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("调用决策试算审批核定金额异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}
	}
	
	
	
	/**云英贷试算审批核定金额查询51公积金
	 * @author 娄凯琦
	 * @date 2018年9月21日  
	 * @param decisionMsgDTO
	 * @return
	 */
	@RequestMapping("YYDTrailApproveAmount")
	@ResponseBody
	public MarvelsResultDTO YYDTrailApproveAmount(@RequestBody DecisionMsgDTO decisionMsgDTO){
		try {
			MarvelsLogUtil.getInstance().info("DecisionController class YYDTrailApproveAmount the method start ==>" + decisionMsgDTO);
			decisionMsgDTO = marvelDecisionService.search51gjj(decisionMsgDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),decisionMsgDTO);
		}catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("调用决策试算审批核定金额异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}
	}
	
	
	
	/**云房贷试算审批核定金额
	 * @author 娄凯琦
	 * @date 2018年9月21日  
	 * @param decisionMsgDTO
	 * @return
	 */
	@RequestMapping("YFDTrailApproveAmount")
	@ResponseBody
	public MarvelsResultDTO YFDTrailApproveAmount(@RequestBody DecisionMsgDTO decisionMsgDTO){ 
		try {
			MarvelsLogUtil.getInstance().info("DecisionController class YYDTrailApproveAmount the method start ==>" + decisionMsgDTO);
			decisionMsgDTO = marvelDecisionService.getShangHaiAmount(decisionMsgDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),decisionMsgDTO);
		}catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(e.getMessage(), e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("调用决策试算审批核定金额异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"系统异常");
		}
	}
}
